Sync fork with upstream PRs #14 and #17 (ordered merge) - #1
Merged
Conversation
…Timeout support Extend the Delphi-Promises library with six new features: 1. Promise.Race<T> - Resolves/rejects with the first settled promise 2. Promise.Any<T> - Resolves with first success, rejects with EAggregateException if all fail 3. Promise.AllSettled<T> - Waits for all promises, returns array of TPromiseSettledResult<T> 4. Cancellation support - ICancellationToken/ICancellationTokenSource with cooperative cancellation 5. .Timeout method - Rejects with ETimeoutException if promise doesn't settle in time 6. Additional .Finally tests - Verifying existing Finally behavior per spec New files: - Core/Types/Next.Core.Promises.Exceptions.pas (EAggregateException, ETimeoutException, EOperationCancelled) - Core/Types/Next.Core.Promises.Cancellation.pas (ICancellationToken, ICancellationTokenSource, TCancellationTokenSource) - Test/Types/TestPromiseRace.pas (8 tests including stress test) - Test/Types/TestPromiseAny.pas (7 tests including stress test) - Test/Types/TestPromiseAllSettled.pas (6 tests including stress test) - Test/Types/TestPromiseFinally.pas (6 tests) - Test/Types/TestPromiseCancellation.pas (9 tests) - Test/Types/TestPromiseTimeout.pas (4 tests) Modified files: - Core/Types/Next.Core.Promises.pas (Race, Any, AllSettled, CancelToken, IsCancelled, OnCancelled, Timeout) - Test/TestNext.dpr (references to new units and test fixtures) https://claude.ai/code/session_01VeVVLGmQXiukbpfM5p7W99
…ents-euyZO Add Promise.Race, Promise.Any, Promise.AllSettled, Cancellation, and Timeout support
Replace 6 non-generic test files with generic versions testing across 5 types (Integer, Boolean, String, TSimpleRecord, TMyObject) plus a new exception type test file. Fix two library bugs discovered during testing: - Promise.Race: use dvKeep + manual loser disposal to prevent double-free of object-typed values - Promise.Any: fix variable capture bug in rejection slot tracking; use atomic counter instead of captured loop index Fix variable capture bugs in AllSettled and Race stress tests by extracting promise creation into helper functions. 750 tests, 0 failures, 0 errors.
…Finally docs Add comprehensive documentation with code examples, comparison tables to JavaScript equivalents, and API reference for all new promise combinators and features.
Co-authored-by: TheOriginalBytePlayer <18058224+TheOriginalBytePlayer@users.noreply.github.com>
Co-authored-by: TheOriginalBytePlayer <18058224+TheOriginalBytePlayer@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
TheOriginalBytePlayer
August 9, 2026 07:40
View session
TheOriginalBytePlayer
marked this pull request as ready for review
August 9, 2026 07:41
There was a problem hiding this comment.
Pull request overview
This PR syncs upstream promise functionality and tests into the fork (merging upstream PRs Laurensvanrun#14 then Laurensvanrun#17), adding higher-level promise combinators and control-flow features (Race/Any/AllSettled/Timeout/Cancellation/Finally), plus related exception types and test coverage.
Changes:
- Added new promise APIs (Race/Any/AllSettled/Timeout/Cancellation/Finally) and supporting types in core units.
- Introduced dedicated exceptions and cancellation-token units.
- Aligned/expanded the DUnitX test suite and updated test project references and documentation.
Reviewed changes
Copilot reviewed 16 out of 28 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Core/Types/Next.Core.Promises.pas | Adds new promise APIs (Race/Any/AllSettled/Timeout/Cancellation/Finally) and updates scheduler/cancellation propagation. |
| Core/Types/Next.Core.Promises.Exceptions.pas | Introduces timeout/cancellation/aggregate exception types used by new APIs. |
| Core/Types/Next.Core.Promises.Cancellation.pas | Adds cancellation token source/token interfaces and implementation. |
| Core/Types/Next.Core.DisposableValue.pas | Refactors locals/inline vars for disposal helpers (likely compiler-compat fixes). |
| Test/Types/TestPromiseTimeout.pas | Adds Timeout behavior tests (success, rejection, custom message, chaining). |
| Test/Types/TestPromiseRace.pas | Adds Race combinator tests including concurrency/stress patterns. |
| Test/Types/TestPromiseFinally.pas | Adds Finally behavior tests (pass-through, replacement on raise, Main thread variant). |
| Test/Types/TestPromiseExceptions.pas | Adds tests validating new exception messages/aggregate behavior. |
| Test/Types/TestPromiseCancellation.pas | Adds cancellation token and CancelToken/OnCancelled behavior tests. |
| Test/Types/TestPromiseAny.pas | Adds Any combinator tests including aggregate-rejection behavior. |
| Test/Types/TestPromiseAllSettled.pas | Adds AllSettled tests for mixed outcomes, ordering, and concurrency. |
| Test/Types/Next.Core.TestPromises.pas | Removes CodeSiteLogging dependency from test harness uses. |
| Test/TestNext.dproj | Registers new core units + new test units in the test project. |
| Test/TestNext.dpr | Adds new units/tests to the DUnitX test runner uses list. |
| Test/Next.Core.Test.Assert.pas | Adds optional Spring4D integration and RTTI fallback in assertions. |
| Test/DelphiMocks/VSoft.DelphiMocks.dspec | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/Tests/MemoryLeakTest/FastMM4Options.inc | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/Tests/.gitignore | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/Source/Delphi.Mocks.inc | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/README.md | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/LICENSE.txt | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/Build/TestAndBuild.fbp8 | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/.gitmodules | Normalizes formatting/line endings (content unchanged). |
| Test/DelphiMocks/.gitignore | Updates ignore patterns; currently contains a merge-artifact marker. |
| readme.md | Expands documentation to cover new combinators/timeout/cancellation/finally. |
| LICENSE | Normalizes formatting/line endings (content unchanged). |
| .github/ISSUE_TEMPLATE/feature_request.md | Normalizes template formatting/line endings. |
| .github/ISSUE_TEMPLATE/bug_report.md | Normalizes template formatting/line endings. |
Suppressed comments (1)
Test/Next.Core.Test.Assert.pas:161
- Assert.AreNotEqualCore: SEqualsErrorStr2 is only declared under {$IFNDEF SPRING4D} but it is used unconditionally. Enabling SPRING4D will make this unit fail to compile due to an undefined identifier.
class procedure Assert.AreNotEqualCore(const expected, actual: TValue; const AMessage: string);
{$IFNDEF SPRING4D}
const
SEqualsErrorStr2 = 'Expected value and actual value should not be equal. Expected: %s Actual: %s %s';
{$ENDIF}
begin
DoAssert;
if expected.Equals(actual) then
FailFmt(SEqualsErrorStr2, [expected.ToString, actual.ToString, AMessage], ReturnAddress)
end;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1004
to
+1011
| APromises[i].ThenBy( | ||
| function(const AValue: T): T | ||
| begin | ||
| Result := AValue; | ||
| if TInterlocked.CompareExchange(LResolved, 1, 0) = 0 then | ||
| TFirstPromise<T>(LOuterPromise).Resolve(AValue); | ||
| end) | ||
| .Catch( |
Comment on lines
+992
to
+994
| SetLength(LExceptions, LTotalCount); | ||
| LLock := TCriticalSection.Create; | ||
|
|
Comment on lines
+1078
to
+1081
| LResult.Status := TPromiseStatus.psRejected; | ||
| LResult.Value := Default(T); | ||
| LResult.Error := APromises[i].GetFailure.Reason; | ||
| end; |
| *.rc | ||
| *.drc | ||
| *.map | ||
| ======= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR brings selected upstream work from
Laurensvanrun/Delphi-Promisesinto the fork by merging PRs in the requested order: Laurensvanrun#14 first, then Laurensvanrun#17. The goal is to align the fork with upstream promise behavior and newly added promise capabilities without rebasing history.Merge scope
Core library updates
Core/Types/Next.Core.Promises.pasand related core types.Core/Types/Next.Core.Promises.Cancellation.pasCore/Types/Next.Core.Promises.Exceptions.pasAPI surface and behavior additions
Race,Any,AllSettled,Timeout,Cancellation,Finally).Test suite alignment